{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">
                        <div class="layui-input-inline layui-form">
                            <select name="status" lay-search="">
                                <option  value="">不限状态</option>
                                <option  value="1">审核中</option>
                                <option  value="2">审核通过</option>
                                <option  value="3">审核失败</option>
                                <option  value="4">出售中</option>
                                <option  value="5">下架</option>
                            </select>
                        </div>
                        <div class="layui-input-inline layui-form">
                            <select name="pool" lay-search="">
                                <option  value="">不限产品池状态</option>
                                <option  value="1">没有加入</option>
                                <option  value="2">审核中</option>
                                <option  value="3">审核通过</option>
                                <option  value="4">审核失败</option>
                            </select>
                        </div>
                        <div class="layui-col-md6 layui-input-inline">
                            <input type="text" id="key" class="layui-input search" name="key" value="" placeholder="店铺名/商品名"/>
                        </div>
                        <div class="layui-input-inline">
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                            <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                        </div>
                    </div>
                </div>
                <!--搜索框结束-->
                {if $Think.session.uid == 1}
                <div class="col-sm-12">
                    <div class="input-group" >
                        <input type="text" disabled class="layui-input" id="tongji1" value="" style="border:1px solid red;color: red;width: 400px;" />
                    </div>
                </div>
                {/if}
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="demo"></table>
                    <!--图片模板-->
                    <script type="text/html" id="imgTpl">
                        <ul class="img_view">
                            {{# if(d.p_banner.length > 0){ }}
                            <li><img src="{{d.p_banner[0]}}" class="img-circle table-img" onerror="this.src='/static/admin/images/head_default.gif'"/></li>
                            {{# if(d.p_banner.length >= 1){ }}
                            {{# for(var i=1;i<d.p_banner.length;i++){  }}
                            <li style="display:none;"><img src="{{d.p_banner[i]}}" ></li>
                            {{# } }}
                            {{# } }}
                            {{# } }}
                        </ul>
                    </script>
                    <!--型号模板-->
                    <script type="text/html" id="modelTpl">
                        {{# if(d.p_model == 1){ }}
                        无型号
                        {{# }else{ }}
                        有型号
                        {{# } }}
                    </script>
                    <script type="text/html" id="postTpl">
                        {{# if(d.p_deliver_cate == 1){ }}
                        包邮
                        {{# }else if(d.p_deliver_cate == 2){ }}
                        到店自提
                        {{# }else if(d.p_deliver_cate == 3){ }}
                        邮费
                        {{# }else{ }}
                        到店消费
                        {{# } }}
                    </script>
                    <!--状态模板-->
                    <script type="text/html" id="staTpl">
                        {{# if(d.p_status == 1){ }}
                        审核中
                        {{# }else if(d.p_status == 2){ }}
                        审核通过
                        {{# }else if(d.p_status == 3){ }}
                        审核失败
                        {{# }else if(d.p_status == 4){ }}
                        出售中
                        {{# }else{ }}
                        下架
                        {{# } }}
                    </script>
                    <script type="text/html" id="adminBar">
                        {{# if(d.p_type == 1){ }}
                        <input type="checkbox" value="{{d.p_id}}" lay-data="1"  lay-skin="switch"  lay-text="加入|取消" lay-filter="OnOff"{{ d.p_admin_tj == 2 ? 'checked' : '' }}  >
                        {{# } }}
                    </script>
                    <script type="text/html" id="admin1Bar">
                        {{# if(d.p_type == 1){ }}
                        <input type="checkbox" value="{{d.p_id}}" lay-data="5"  lay-skin="switch"  lay-text="加入|取消" lay-filter="OnOff"{{ d.p_admin_tj_zong == 2 ? 'checked' : '' }}  >
                        {{# } }}
                    </script>
                    <script type="text/html" id="headBar">
                        {{# if(d.p_type == 1){ }}
                        <input type="checkbox" value="{{d.p_id}}" lay-data="2"  lay-skin="switch"  lay-text="加入|取消" lay-filter="OnOff"{{ d.p_head_tj == 2 ? 'checked' : '' }}  >
                        {{# } }}
                    </script>
                    <script type="text/html" id="youBar">
                        {{# if(d.p_type == 1){ }}
                        <input type="checkbox" value="{{d.p_id}}" lay-data="3"  lay-skin="switch"  lay-text="加入|取消" lay-filter="OnOff"{{ d.p_you_tj == 2 ? 'checked' : '' }}  >
                        {{# } }}
                    </script>
                    <script type="text/html" id="searchBar">
                        {{# if(d.p_type == 1){ }}
                        <input type="checkbox" value="{{d.p_id}}" lay-data="4"  lay-skin="switch"  lay-text="加入|取消" lay-filter="OnOff"{{ d.p_search == 2 ? 'checked' : '' }}  >
                        {{# } }}
                    </script>
                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        {{# if(d.p_status == 1){ }}
                        <a href="javascript:;" onclick="check({{d.p_id}})"  class="btn btn-primary btn-xs m-r-xs">审核</a>
                        {{# } }}
                        {{# if(d.p_status == 4){ }}
                        <a href="javascript:;" onclick="wk.confirm({{d.p_id}},'{:url('soldOut')}','确认下架此商品吗？')"  class="btn btn-danger btn-xs m-r-xs">下架</a>
                        {{# } }}
                        {{# if(d.p_model == 2){ }}
                        <a href="javascript:;" onclick="wk.href('{:url('seeModel')}?id={{d.p_id}}')"  class="btn btn-primary btn-xs m-r-xs">查看型号</a>
                        {{# } }}
                        <a href="javascript:;" lay-event="detail"  class="btn btn-info btn-xs m-r-xs">查看商品详情</a>
                        <a href="javascript:;" onclick="son({{d.p_id}})" class="btn btn-primary btn-xs m-r-xs" >排序</a>
                        {{# if(d.p_status == 4 && d.sessionUid != 1){ }}
                            {{# if(d.p_m_pool == 1){ }}
                                <a href="javascript:;" onclick="wk.confirm({{d.p_id}},'{:url('inPoll')}','确认要申请此商品进入产品池吗？')"  class="btn btn-warning btn-xs m-r-xs">申请产品池</a>
                            {{# }else{ }}
                                {{# if(d.p_m_pool == 2){ }}<span>审核中</span>{{# } }}
                                {{# if(d.p_m_pool == 3){ }}<span style="color: mediumseagreen;">已通过</span>{{# } }}
                                {{# if(d.p_m_pool == 4){ }}<span style="color: orangered;">已拒绝</span>{{# } }}
                            {{# } }}
                        {{# } }}
                        {{# if(d.p_status == 4 && d.sessionUid == 1){ }}
                            {{# if(d.p_m_pool == 2){ }}
                                <a href="javascript:;" onclick="wk.layer_show('产品池审核', '{:url('checkPoll')}?p_id={{d.p_id}}&type=1')" class="btn btn-warning btn-xs m-r-xs" title="产品池审核"><i class="fa fa-edit">产品池审核</i></a>
                            {{# } }}
                            {{# if(d.p_m_pool == 3){ }}
                                <a href="javascript:;" onclick="wk.layer_show('产品池分佣设置', '{:url('checkPoll')}?p_id={{d.p_id}}&type=2')" class="btn btn-warning btn-xs m-r-xs" title="产品池分佣设置"><i class="fa fa-edit">产品池分佣设置</i></a>
                            {{# } }}
                            {{# if(d.p_m_pool == 4){ }}<span style="color: orangered;">已拒绝</span>{{# } }}
                        {{# } }}
                    </script>
                    <!-- 修改销量 -->
                    <script type="text/html" id="updateSellTpl">
                        <span>{{ d.p_sell_yet }}</span>
                        <a href="javascript:;" onclick="showUpdateSell({{d.p_id}})" class="btn btn-info btn-xs m-r-xs">修改</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
            , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("Product/cash")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type:'numbers', width: 80, title: '序号'}
                , {field: 'shop_name', width: '', title: '店铺名', align: 'center'}
                , {field: 'p_name', width: '', title: '商品名', align: 'center'}
                , {field: 'p_banner', width: 90, title: '商品图片', align: 'center', templet: '#imgTpl'}
                , {field: 'cate_name', width: '', title: '分类', align: 'center'}
                , {field: 'p_old_price', width: '', title: '原价', align: 'center'}
                , {field: 'p_now_price', width: '', title: '现价',  align: 'center'}
                , {field: 'p_stock_num', width: '', title: '库存', align: 'center'}
                , {field: 'p_sell_yet', width: '', title: '已售库存', align: 'center', templet:'#updateSellTpl'}
                , {field: 'p_content', width: '', title: '商品详情', align: 'center'}
                , {field: 'p_deliver_cate', width: '', title: '配送方式', align: 'center',templet:'#postTpl'}
                , {field: 'p_model', width: '', title: '型号', align: 'center',templet:'#modelTpl'}
                , {field: 'p_status', width: '', title: '状态', align: 'center',templet:'#staTpl'}
                , {fixed: '',field:'p_sort', width: 80, title: '排序值', align: 'center'}
                , {fixed: '', width: 100, title: '城主推荐', align: 'center',templet: '#adminBar'}
                , {fixed: '', width: 130, title: '总部推荐', align: 'center', templet: '#headBar',hide:'{:session("uid") == 1? false : true}'}
                , {fixed: '', width: 130, title: '为你推荐(总部)', align: 'center', templet: '#youBar',hide:'{:session("uid") == 1? false : true}'}
                , {fixed: '', width: 130, title: '热门搜索(总部)', align: 'center', templet: '#searchBar',hide:'{:session("uid") == 1? false : true}'}
                , {fixed: '', width: 130, title: '城主推荐(总部)', align: 'center',templet: '#admin1Bar',hide:'{:session("uid") == 1? false : true}'}
                , {fixed: 'right', width: 400, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]],
            done: function (res, curr, count) {
                $('.img_view').viewer();
                $('#tongji1').val('待审核产品池商品数：' + res.needPoll);
            }
        });
        form.on('switch(OnOff)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 2: num = 1;
            var type = $(obj.elem).attr('lay-data');
            //用户状态
            wk.status(this.value,num, '{:url("goodsStatus2")}',obj,type);
        });

        //监听工具条
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                wk.layer_show1('商品详情',data.p_content)
            }
        });
    });

    function check(p_id) {
        layer.confirm('审核是否通过吗?', {
            icon: 3,
            title:'提示',
            btn: ['通过', '驳回'],
            btn2:function(index){
                send(p_id,3);
                layer.close(index);
            }}, function(index){
            send(p_id,4);
            layer.close(index);
        });
    }
    function send(p_id,type){
        $.ajax({
            url: "{:url('doCheck')}",
            type: "post",
            dataType: "json",
            data: {p_id:p_id,type:type},
            success: function (res) {
                if(res.code == 200){
                    layer.msg(res.msg,{icon:1,time:1500,shade: 0.1},function(){
                        //重载当前页表格
                        $(".layui-laypage-btn").click();
                    });
                } else if (res.code == 100){
                    layer.msg(res.msg,{icon:2,time:1500,shade: 0.1});
                }
            }
        });
    }
    function son(shop_id) {
        layer.prompt({
            formType: 2,
            title: '修改排序值',
            area: ['200px', '50px'],
            btn: ['确认', '取消'],
            maxlength:11,
        },function(value, index, elem){
            var pattern = /^[1-9]\d*$/;
            if(!pattern.test(value)){
                wk.error('请填写正确的排序值');
                return;
            }
            send1(shop_id,value);
            layer.close(index);
        });
    }
    function send1(shop_id,value){
        $.ajax({
            url: "{:url('addSort')}",
            type: "post",
            dataType: "json",
            data: {id:shop_id,num:value},
            success: function (res) {
                if(res.code == 200){
                    layer.msg(res.msg,{icon:1,time:1500,shade: 0.1},function(){
                        //重载当前页表格
                        $(".layui-laypage-btn").click();
                    });
                } else if (res.code == 100){
                    layer.msg(res.msg,{icon:2,time:1500,shade: 0.1});
                }
            }
        });
    }
    // 修改销量
    function showUpdateSell(shop_id) {
        layer.prompt({
            formType: 2,
            title: '修改销量',
            area: ['200px', '50px'],
            btn: ['确认', '取消'],
            maxlength:11,
        },function(value, index, elem){
            var pattern = /^[1-9]\d*$/;
            if(!pattern.test(value)){
                wk.error('请填写数字');
                return;
            }
            doUpdateSell(shop_id,value);
            layer.close(index);
        });
    }
    function doUpdateSell(shop_id,value){
        $.ajax({
            url: "{:url('updateSell')}",
            type: "post",
            dataType: "json",
            data: {id:shop_id,num:value},
            success: function (res) {
                if(res.code == 200){
                    layer.msg(res.msg,{icon:1,time:1500,shade: 0.1},function(){
                        //重载当前页表格
                        $(".layui-laypage-btn").click();
                    });
                } else if (res.code == 100){
                    layer.msg(res.msg,{icon:2,time:1500,shade: 0.1});
                }
            }
        });
    }
</script>
</body>
</html>